package com.ailk.kbi.kbirazor.component
{
	
	import com.ailk.kbi.kbirazor.component.LinkLine;
	import com.ailk.kbi.kbirazor.component.NodeGroup;
	import com.ailk.kbi.kbirazor.model.KbrModel;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.graphics.SolidColorStroke;
	import mx.states.State;
	
	import spark.components.Group;
	import spark.primitives.Ellipse;
	import spark.primitives.Line;
	
	
	public class Anchor extends Group{
		private var _contentXML:XML;
		
		private var ellipse:Ellipse;
		
		private var lineVertical:Line;
		private var lineHorizontal:Line;
		
		private var _close:Boolean = false;
		
		[Bindable]
		private var kbrModel:KbrModel = KbrModel.getInstance();
		
		public function Anchor(contentXML:XML){
			super();
			_contentXML = contentXML;			
			updateChildren();
		}
		
		public function updateChildren():void{	
			if(_contentXML.hasOwnProperty('@close') && _contentXML.@close == 'true'){
				_close = true;
			}
			
			ellipse = new Ellipse();  
			ellipse.stroke = new SolidColorStroke(0x006da3,1); 
			addElement(ellipse);
			with(ellipse){
				height=11;
				width=11;
			}
			
			if(_close){
				lineVertical = new Line();  
				lineVertical.stroke = new SolidColorStroke(0x006da3,1); 
				addElement(lineVertical);
				with(lineVertical){
					xFrom=5;
					xTo=5;
					yFrom=1;
					yTo=10;
				}
				
				
			}
			
			lineHorizontal = new Line();  
			lineHorizontal.stroke = new SolidColorStroke(0x006da3,1); 
			addElement(lineHorizontal);
			with(lineHorizontal){
				xFrom = 1;
				xTo = 10;
				yFrom = 5.5;
				yTo = 5.5;
			}
			
			this.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		public function get close():Boolean{
			return _close;
		}
		
		public function set close(flag:Boolean):void {
			_close = flag;
		}
		
		protected function clickHandler(event:Event):void
		{
			_close = !_close;
			_contentXML.@close = _close;
			kbrModel.anchorChange();
		}
	}
}